﻿using System;
using System.Collections.Generic;
using SharpSqlAnalyzer.nodes;
using SharpSqlAnalyzer.nodes.mssql;

namespace SharpSqlAnalyzer.stmt.mssql
{
	// Token: 0x02000168 RID: 360
	public class TMssqlCreateFunction : TStoredProcedureSqlStatement
	{
		// Token: 0x1700023C RID: 572
		// (get) Token: 0x06000C51 RID: 3153 RVA: 0x0030722D File Offset: 0x0030542D
		// (set) Token: 0x06000C50 RID: 3152 RVA: 0x00307224 File Offset: 0x00305424
		public virtual List<TProcedureOption> ProcedureOptions
		{
			get
			{
				return this.procedureOptions;
			}
			set
			{
				this.procedureOptions = value;
			}
		}

		// Token: 0x06000C52 RID: 3154 RVA: 0x00307235 File Offset: 0x00305435
		public TMssqlCreateFunction(EDbVendor dbvendor) : base(dbvendor)
		{
			this.sqlstatementtype = ESqlStatementType.sstmssqlcreatefunction;
		}

		// Token: 0x06000C53 RID: 3155 RVA: 0x00307254 File Offset: 0x00305454
		internal override void buildsql()
		{
		}

		// Token: 0x06000C54 RID: 3156 RVA: 0x00307256 File Offset: 0x00305456
		internal override void clear()
		{
		}

		// Token: 0x06000C55 RID: 3157 RVA: 0x00307258 File Offset: 0x00305458
		internal override string getasprettytext()
		{
			return "";
		}

		// Token: 0x06000C56 RID: 3158 RVA: 0x0030725F File Offset: 0x0030545F
		internal virtual void iterate(TVisitorAbs pvisitor)
		{
		}

		// Token: 0x1700023D RID: 573
		// (get) Token: 0x06000C57 RID: 3159 RVA: 0x00307261 File Offset: 0x00305461
		public override TObjectName StoredProcedureName
		{
			get
			{
				return this.functionName;
			}
		}

		// Token: 0x1700023E RID: 574
		// (get) Token: 0x06000C58 RID: 3160 RVA: 0x00307269 File Offset: 0x00305469
		// (set) Token: 0x06000C59 RID: 3161 RVA: 0x00307271 File Offset: 0x00305471
		public virtual TObjectName FunctionName
		{
			get
			{
				return this.functionName;
			}
			set
			{
				this.functionName = value;
			}
		}

		// Token: 0x1700023F RID: 575
		// (get) Token: 0x06000C5A RID: 3162 RVA: 0x0030727A File Offset: 0x0030547A
		// (set) Token: 0x06000C5B RID: 3163 RVA: 0x00307282 File Offset: 0x00305482
		public virtual int ReturnMode
		{
			get
			{
				return this.returnMode;
			}
			set
			{
				this.returnMode = value;
			}
		}

		// Token: 0x17000240 RID: 576
		// (get) Token: 0x06000C5C RID: 3164 RVA: 0x0030728B File Offset: 0x0030548B
		// (set) Token: 0x06000C5D RID: 3165 RVA: 0x00307293 File Offset: 0x00305493
		public virtual TMssqlBlock Block
		{
			get
			{
				return this.block;
			}
			set
			{
				this.block = value;
			}
		}

		// Token: 0x17000241 RID: 577
		// (get) Token: 0x06000C5E RID: 3166 RVA: 0x0030729C File Offset: 0x0030549C
		// (set) Token: 0x06000C5F RID: 3167 RVA: 0x003072A4 File Offset: 0x003054A4
		public virtual TMssqlReturn ReturnStmt
		{
			get
			{
				return this.returnStmt;
			}
			set
			{
				this.returnStmt = value;
			}
		}

		// Token: 0x17000242 RID: 578
		// (get) Token: 0x06000C60 RID: 3168 RVA: 0x003072AD File Offset: 0x003054AD
		// (set) Token: 0x06000C61 RID: 3169 RVA: 0x003072B5 File Offset: 0x003054B5
		public virtual TObjectName ReturnTableVaraible
		{
			get
			{
				return this.returnTableVaraible;
			}
			set
			{
				this.returnTableVaraible = value;
			}
		}

		// Token: 0x17000243 RID: 579
		// (get) Token: 0x06000C62 RID: 3170 RVA: 0x003072BE File Offset: 0x003054BE
		// (set) Token: 0x06000C63 RID: 3171 RVA: 0x003072C6 File Offset: 0x003054C6
		public virtual TTableElementList ReturnTableDefinitions
		{
			get
			{
				return this.returnTableDefinitions;
			}
			set
			{
				this.returnTableDefinitions = value;
			}
		}

		// Token: 0x17000244 RID: 580
		// (get) Token: 0x06000C64 RID: 3172 RVA: 0x003072CF File Offset: 0x003054CF
		// (set) Token: 0x06000C65 RID: 3173 RVA: 0x003072D7 File Offset: 0x003054D7
		public virtual TTypeName ReturnDataType
		{
			get
			{
				return this.returnDataType;
			}
			set
			{
				this.returnDataType = value;
			}
		}

		// Token: 0x17000245 RID: 581
		// (get) Token: 0x06000C66 RID: 3174 RVA: 0x003072E0 File Offset: 0x003054E0
		// (set) Token: 0x06000C67 RID: 3175 RVA: 0x0030730D File Offset: 0x0030550D
		public virtual int FunctionType
		{
			get
			{
				int result = this.functionType;
				if (this.returnMode == 3)
				{
					result = 3;
				}
				else if (this.returnMode == 2)
				{
					result = 2;
				}
				return result;
			}
			set
			{
				this.functionType = value;
			}
		}

		// Token: 0x06000C68 RID: 3176 RVA: 0x00307318 File Offset: 0x00305518
		public override int doParseStatement(TCustomSqlStatement psql)
		{
			if (this.rootNode == null)
			{
				return -1;
			}
			if (!(this.rootNode is TCreateFunctionSqlNode))
			{
				return -1;
			}
			TCreateFunctionSqlNode tcreateFunctionSqlNode = (TCreateFunctionSqlNode)this.rootNode;
			base.doParseStatement(psql);
			this.functionName = tcreateFunctionSqlNode.FunctionName;
			this.procedureOptions = tcreateFunctionSqlNode.ProcedureOptions;
			base.DatabaseObjects.Add(this.functionName);
			this.ParameterDeclarations = tcreateFunctionSqlNode.Parameters;
			if (tcreateFunctionSqlNode.ReturnDataType != null)
			{
				this.returnMode = 1;
				this.returnDataType = tcreateFunctionSqlNode.ReturnDataType;
			}
			else if (tcreateFunctionSqlNode.ReturnTable != null)
			{
				TDummy returnTable = tcreateFunctionSqlNode.ReturnTable;
				if (returnTable.node1 != null)
				{
					this.returnMode = 3;
					this.returnTableVaraible = (TObjectName)returnTable.node1;
					this.returnTableVaraible.ObjectType = 10;
					this.returnTableDefinitions = (TTableElementList)returnTable.list1;
					this.returnTableDefinitions.doParse(this, ESqlClause.unknown);
				}
				else
				{
					this.returnMode = 2;
				}
			}
			if (this.ParameterDeclarations != null)
			{
				for (int i = 0; i < this.ParameterDeclarations.size(); i++)
				{
					this.TopStatement.SymbolTable.Push(new TSymbolTableItem(9, this, this.ParameterDeclarations.getParameterDeclarationItem(i)));
				}
			}
			if (tcreateFunctionSqlNode.Blcok != null)
			{
				this.block = new TMssqlBlock(this.dbvendor);
				this.block.rootNode = tcreateFunctionSqlNode.Blcok;
				this.block.doParseStatement(this);
				this.BodyStatements.add(this.block);
			}
			if (tcreateFunctionSqlNode.ReturnSqlNode != null)
			{
				this.returnStmt = new TMssqlReturn(this.dbvendor);
				this.returnStmt.rootNode = tcreateFunctionSqlNode.ReturnSqlNode;
				this.returnStmt.doParseStatement(this);
				this.BodyStatements.add(this.returnStmt);
			}
			if (this.ParameterDeclarations != null)
			{
				for (int j = 0; j < this.ParameterDeclarations.size(); j++)
				{
					this.TopStatement.SymbolTable.Pop();
				}
			}
			return 0;
		}

		// Token: 0x06000C69 RID: 3177 RVA: 0x00307509 File Offset: 0x00305709
		public override void accept(TParseTreeVisitor v)
		{
			v.preVisit(this);
			v.postVisit(this);
		}

		// Token: 0x06000C6A RID: 3178 RVA: 0x0030751C File Offset: 0x0030571C
		public override void acceptChildren(TParseTreeVisitor v)
		{
			v.preVisit(this);
			if (this.ParameterDeclarations != null)
			{
				this.ParameterDeclarations.acceptChildren(v);
			}
			if (this.BodyStatements.size() > 0)
			{
				this.BodyStatements.acceptChildren(v);
			}
			if (this.returnStmt != null)
			{
				this.returnStmt.acceptChildren(v);
			}
			v.postVisit(this);
		}

		// Token: 0x040012D7 RID: 4823
		private List<TProcedureOption> procedureOptions;

		// Token: 0x040012D8 RID: 4824
		private TMssqlBlock block;

		// Token: 0x040012D9 RID: 4825
		private TMssqlReturn returnStmt;

		// Token: 0x040012DA RID: 4826
		private TObjectName functionName;

		// Token: 0x040012DB RID: 4827
		private int returnMode = 1;

		// Token: 0x040012DC RID: 4828
		private TObjectName returnTableVaraible;

		// Token: 0x040012DD RID: 4829
		private TTableElementList returnTableDefinitions;

		// Token: 0x040012DE RID: 4830
		private TTypeName returnDataType;

		// Token: 0x040012DF RID: 4831
		private int functionType = 1;
	}
}
